﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace AutomationCommand
{
    public  class UnitCommand
    {
        /// <summary>
        /// 被操作的：谷哥浏览器
        /// </summary>
        public OpenQA.Selenium.Chrome.ChromeDriver chromeDriver = null;

        //被操作的：手机
        public object mobile = null;

        /// <summary>
        /// 被操作的线程
        /// </summary>
        public List<Process> processes = new List<Process>();


        public Dictionary<string, BasiCommand> commandDictionary = new Dictionary<string, BasiCommand>();

        public UnitCommand()
        {
            commandDictionary.Add("wb_brws_got", wb_Brws_Got);
            commandDictionary.Add("wb_brws_swt", wb_Brws_Swt);
            commandDictionary.Add("wb_data_api", wb_Data_Api);
            commandDictionary.Add("wb_data_delete", wb_Data_Delete);
            commandDictionary.Add("wb_data_local_manage", wb_Data_Local_Manage);
            commandDictionary.Add("wb_data_read", wb_Data_Read);
            commandDictionary.Add("wb_data_read_new", wb_Data_Read_New);
            commandDictionary.Add("wb_data_remote_manage", wb_Data_Remote_Manage);
            commandDictionary.Add("wb_data_test", wb_Data_Test);
            commandDictionary.Add("wb_element_cut", wb_Element_Cut);
            commandDictionary.Add("wb_elmt_ckimg", wb_Elmt_Ckimg);
            commandDictionary.Add("wb_elmt_clk", wb_Elmt_Clk);
            commandDictionary.Add("wb_elmt_cod", wb_Elmt_Cod);
            commandDictionary.Add("wb_elmt_rfs", wb_Elmt_Rfs);
            commandDictionary.Add("wb_elmt_snd", wb_Elmt_Snd);
            commandDictionary.Add("wb_elmt_wit", wb_Elmt_Wit);
            commandDictionary.Add("wb_elmt_wit_clk", wb_Elmt_Wit_Clk);
            commandDictionary.Add("wb_elmt_wit_snd", wb_Elmt_Wit_Snd);
            commandDictionary.Add("wb_gst_elmt_wit_opt", wb_Gst_Elmt_Wit_Opt);
            commandDictionary.Add("wb_just_wit", wb_Just_Wit);
            commandDictionary.Add("wb_lst_elmt_wit_opt", wb_Lst_Elmt_Wit_Opt);
            commandDictionary.Add("wb_no_spider", wb_No_Spider);
            commandDictionary.Add("wb_open_pg", wb_Open_Pg);
            commandDictionary.Add("wb_page_data", wb_Page_Data);
            commandDictionary.Add("wb_waterfall_opt", wb_Waterfall_Opt);
            commandDictionary.Add("data_http_get", data_Http_Get);
            commandDictionary.Add("data_import", data_Import);
            commandDictionary.Add("data_input", data_Input);
            commandDictionary.Add("ml_connect", ml_connect);
            commandDictionary.Add("ml_divice_option", ml_Divice_Option);
            commandDictionary.Add("ml_elmt_date", ml_elmt_date);
            commandDictionary.Add("ml_elmt_wit_clk", ml_Elmt_Wit_Clk);
            commandDictionary.Add("ml_elmt_wit_snd", ml_Elmt_Wit_Snd);
            commandDictionary.Add("ml_lst_elmt_wit_opt", ml_Lst_Elmt_Wit_Opt);
            commandDictionary.Add("ml_shell_option", ml_Shell_Option);
            commandDictionary.Add("open_app", open_App);
            commandDictionary.Add("autoitX", autoitX);
            commandDictionary.Add("excel_option", excel_Option);
            commandDictionary.Add("file_list_import", file_List_Import);
            commandDictionary.Add("opcv_ocr_click", opcv_Ocr_Click);
            commandDictionary.Add("opcv_ocr_wrtin", opcv_Ocr_Wrtin);
            commandDictionary.Add("opcv_option", opcv_Option);
            commandDictionary.Add("ppt_make", ppt_Make);
            commandDictionary.Add("ppt_pic_option", ppt_Pic_Option);
            commandDictionary.Add("table_read", table_Read);
        }
        #region 浏览器操作
        public wb_brws_got wb_Brws_Got = new wb_brws_got();
        public wb_brws_swt wb_Brws_Swt = new wb_brws_swt();
        public wb_data_api wb_Data_Api = new wb_data_api();
        public wb_data_delete wb_Data_Delete = new wb_data_delete();
        public wb_data_local_manage wb_Data_Local_Manage = new wb_data_local_manage();
        public wb_data_read wb_Data_Read = new wb_data_read();
        public wb_data_read_new wb_Data_Read_New = new wb_data_read_new();
        public wb_data_remote_manage wb_Data_Remote_Manage = new wb_data_remote_manage();
        public wb_data_test wb_Data_Test = new wb_data_test();
        public wb_element_cut wb_Element_Cut = new wb_element_cut();
        public wb_elmt_ckimg wb_Elmt_Ckimg = new wb_elmt_ckimg();
        public wb_elmt_clk wb_Elmt_Clk = new wb_elmt_clk();
        public wb_elmt_cod wb_Elmt_Cod = new wb_elmt_cod();
        public wb_elmt_rfs wb_Elmt_Rfs = new wb_elmt_rfs();
        public wb_elmt_snd wb_Elmt_Snd = new wb_elmt_snd();
        public wb_elmt_wit wb_Elmt_Wit = new wb_elmt_wit();
        public wb_elmt_wit_clk wb_Elmt_Wit_Clk = new wb_elmt_wit_clk();
        public wb_elmt_wit_snd wb_Elmt_Wit_Snd = new wb_elmt_wit_snd();
        public wb_gst_elmt_wit_opt wb_Gst_Elmt_Wit_Opt = new wb_gst_elmt_wit_opt();
        public wb_just_wit wb_Just_Wit = new wb_just_wit();
        public wb_lst_elmt_wit_opt wb_Lst_Elmt_Wit_Opt = new wb_lst_elmt_wit_opt();
        public wb_no_spider wb_No_Spider = new wb_no_spider();
        public wb_open_pg wb_Open_Pg = new wb_open_pg();
        public wb_page_data wb_Page_Data = new wb_page_data();
        public wb_waterfall_opt wb_Waterfall_Opt = new wb_waterfall_opt();
        #endregion

        #region 数据操作
        public data_http_get data_Http_Get = new data_http_get();
        public data_import data_Import = new data_import();
        public data_input data_Input = new data_input();
        #endregion

        #region 手机操作
        public ml_connect ml_connect = new ml_connect();
        public ml_divice_option ml_Divice_Option = new ml_divice_option();
        public ml_elmt_date ml_elmt_date = new ml_elmt_date();
        public ml_elmt_wit_clk ml_Elmt_Wit_Clk = new ml_elmt_wit_clk();
        public ml_elmt_wit_snd ml_Elmt_Wit_Snd = new ml_elmt_wit_snd();
        public ml_lst_elmt_wit_opt ml_Lst_Elmt_Wit_Opt = new ml_lst_elmt_wit_opt();
        public ml_shell_option ml_Shell_Option = new ml_shell_option();
        public open_app open_App = new open_app();
        #endregion

        #region 系统操作
        public autoitX autoitX = new autoitX();
        public excel_option excel_Option = new excel_option();
        public file_list_import file_List_Import = new file_list_import();
        public opcv_ocr_click opcv_Ocr_Click = new opcv_ocr_click();
        public opcv_ocr_wrtin opcv_Ocr_Wrtin = new opcv_ocr_wrtin();
        public opcv_option opcv_Option = new opcv_option();
        public ppt_make ppt_Make = new ppt_make();
        public ppt_pic_option ppt_Pic_Option = new ppt_pic_option();
        public table_read table_Read = new table_read();
        #endregion

    }




    /// <summary>
    /// 基础命令执行
    /// </summary>
    public class BasiCommand
    {
        [JsonProperty("fun_type")]
        public string FunctionType { get; set; }

        [JsonProperty("othername")]
        public string OtherName { get; set; }

        [JsonProperty("taskid")]
        public long TaskId { get; private set; }

        [JsonProperty("jumpid")]
        public long JumpId { get; private set; }

        [JsonProperty("s_jump")]
        public long SuccessJump { get; set; }

        [JsonProperty("f_jump")]
        public long FailureJump { get; set; }

        // 构造函数，在创建命令对象时生成唯一ID
        public BasiCommand()
        {
            // 生成当前时间的13位时间戳（毫秒级）
            JumpId = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
            TaskId = GenerateTaskId();
        }

        // 方法用于执行命令，子类需要实现具体逻辑
        public virtual bool Execute(JObject command,object vessel)
        {
            // 具体执行逻辑由子类实现
            return true;
        }

        // 生成任务ID的方法，可以根据实际需求进行实现
        private long GenerateTaskId()
        {
            // 在这里添加生成任务ID的逻辑，这里只是一个示例
            return JumpId; // 为示例，将TaskId设置为JumpId
        }
    }


}
